package com.nineclock.attendance.controller;


import com.nineclock.attendance.dto.HolidayRuleDto;
import com.nineclock.attendance.dto.MakeUpDTO;
import com.nineclock.attendance.dto.MakeupDtoT;
import com.nineclock.attendance.service.AttendGroupService;
import com.nineclock.attendance.service.MakeUpService;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/rule")
@Api(value = "假期管理")
@Slf4j
public class HolidayController {

    @Autowired
    private AttendGroupService attendGroupService;

    @Autowired
    private MakeUpService makeUpService;

    /*
     *查询假期
     * */
    @GetMapping("/holiday")
    @ApiOperation("查询假期")
    public Result<PageResult<HolidayRuleDto>> holiday(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer pageSize){
        PageResult<HolidayRuleDto> pageResult = attendGroupService.holiday(page,pageSize);
        return Result.success(pageResult);
    }

    /*
     * 添加假期
     * */
    @PostMapping("/holiday")
    @ApiOperation("添加假期")
    public Result addHoliday(@RequestBody HolidayRuleDto holidayRuleDto){
        attendGroupService.addHoliday(holidayRuleDto);
        return Result.success();
    }

    /*
     * 修改假期
     * */
    @PutMapping("/holiday/{id}")
    @ApiOperation("修改假期")
    public Result putHoliday(@PathVariable Long id ,@RequestBody HolidayRuleDto holidayRuleDto){
        attendGroupService.putHoliday(id,holidayRuleDto);
        return Result.success();
    }

    /*
    * 删除假期
    * */
    @DeleteMapping("/holiday/{id}")
    @ApiOperation("删除假期")
    public Result deleteHoliday(@PathVariable Long id){
        attendGroupService.deleteHoliday(id);
        return Result.success();
    }


    /*
    * 分页查询补卡规则
    * */
    @GetMapping("/makeup")
    @ApiOperation("分页查询补卡规则")
    public Result<PageResult<MakeUpDTO>> makeupPage(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "5")Integer pageSize){
        PageResult<MakeUpDTO> makeUpDTOPageResult = makeUpService.makeupPage(page,pageSize);
        return Result.success(makeUpDTOPageResult);
    }


    /*
    * 编辑补卡规则
    * */
    @PutMapping("/makeup/{id}")
    @ApiOperation("编辑补卡规则")
    public Result makeupPut(@PathVariable Long id, @RequestBody MakeUpDTO makeUpDTO){

        makeUpService.makeupPut(makeUpDTO);

        return Result.success();
    }
}
